package puzzle.projecteuler.p300;

import astudy.util.AdvMath;


public class Problem202B {

	public static void main(String[] args) {

		long s = System.currentTimeMillis();
		System.out.println(p202(12017639147L));
		System.out.println("Time: " + (System.currentTimeMillis()-s) + " ms");
	}
	
	/**
	 * solution of 
	 * x+y = (n+3)/2
	 * 3|x-y
	 * gcd(x,y)=1
	 * x, y >= 1
	 * @param n
	 * @return
	 */
	private static long p202(long n) {
		
		long m = (n+3)/2;
		Long[] ds = AdvMath.primeDivisor(m);
		long c = 0;
		for (long k = 0; k <= (m-2)/3; k ++) {
			if ((m-k)%2 == 0) {
				long x = (m-3*k)/2;
				long y = (m+3*k)/2;
				long g = AdvMath.gcd(x,y);
				//check
				boolean b = true;
				for (Long d: ds) {
					if (g%d == 0) {
						b = false;
						break;
					}
				}
				if (b) {
					c ++;
				}
			}
		}
		return 2*c;
	}
	

}
